
//
//  YKPostViewController.m
//  baisi
//
//  Created by 吴高烽 on 2016/10/30.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKPostViewController.h"
#import "YKPlaceholderTextView.h"
#import "YKAddTagToolbar.h"
@interface YKPostViewController ()<UITextViewDelegate>
@property (nonatomic ,weak)YKPlaceholderTextView *textView;
@property (nonatomic ,weak) YKAddTagToolbar *toolBar;
@end

@implementation YKPostViewController
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.view endEditing:YES];
    [self.textView becomeFirstResponder];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    [self setupTextView];
    [self setupToolBar];
}
-(void)setupNav{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"发表文字";
//    ios7以后uibarbuttonitemstyle的样式没有什么区别了
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发表" style:UIBarButtonItemStyleDone target:self action:@selector(postWord)];
    self.navigationItem.rightBarButtonItem.enabled = NO ;
//    强制刷新导航栏上的按钮
    [self.navigationController.navigationBar layoutIfNeeded];
    
}
-(void)setupTextView{
    YKPlaceholderTextView *textView = [YKPlaceholderTextView new];
    textView.frame = self.view.bounds ;
    textView.delegate = self ;
    textView.placeholder = @"把好玩的图片，好笑的段子或糗事发到这里，接受千万网友膜拜吧！发布违反国家法律内容的，我们将依法提交给有关部门处理。" ;
    [self.view addSubview:textView];
    self.textView = textView ;
    [textView becomeFirstResponder];
}
-(void)setupToolBar{
    YKAddTagToolbar *toolbar = [YKAddTagToolbar addTagToolbar];
    toolbar.width = self.view.width ;
    toolbar.y = self.view.height - toolbar.height ;
    [self.view addSubview:toolbar];
    self.toolBar = toolbar ;
    [YKNotiCenter addObserver:self selector:@selector(keyboardFrameChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
-(void)cancel{
    [self dismissViewControllerAnimated:YES completion:nil];
}

/**
 发表内容
 */
-(void)postWord{
    
}
-(void)keyboardFrameChange:(NSNotification*)noti{
    YKLog(@"%@",noti);
    CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey]doubleValue];
    [UIView animateWithDuration:duration animations:^{
        self.toolBar.transform = CGAffineTransformMakeTranslation(0, frame.origin.y - SCHeight);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [self.view endEditing: YES ];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
